<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<%@ include file="global.jsp" %>
<%
String id = request.getParameter("id");
String likedBy = request.getParameter("likedBy");
String likes = request.getParameter("");
likes = likes +", "+likedBy;

if(id != null && likedBy != null){
	if(id.indexOf(likedBy) > 0){
		System.out.println("Already Liked");
	}else{
		
	String success = "";
	try{
		System.out.println("Commented IP: "+request.getRemoteAddr()+":::"+request.getParameter("comments"));
		Class.forName(db_driver);
		Connection conn = DriverManager.getConnection(db_url, db_user, db_password);
		String query = "UPDATE answers SET likes='"+likes+"' WHERE Id="+id+" LIMIT 1";
		PreparedStatement pstmt = conn.prepareStatement(query);
		pstmt.executeUpdate();
		pstmt.close();	
		conn.close();
		success ="Updated Succesfully";
		} 
		 catch (Exception e){
		      e.printStackTrace();
		      success ="Failure in insertion";
		} 
	}
}
response.sendRedirect("TodaysQuiz.jsp");
%>
